// pages/auth/auth.js
let App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    edit_disable:true,
    inputcolor:'#f6f6f6',
    name1:'',
    mobile1:'',
    relation1:'',
    name2:'',
    mobile2:'',
    relation2:'',
    real_name:'',
    mobile:'',
    idcard:'',
    address:'',
    id:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
  },
/**
   * 编辑
   */
  edit_able:function(){
    this.setData({
      edit_disable:false,
      inputcolor:'#fff'
    })
  },
  /**
   * 保存
   */
  savecustomerrelation:function(){
    let data = {
      name1 : this.data.name1,
      mobile1 : this.data.mobile1,
      relation1 : this.data.relation1,
      name2 : this.data.name2,
      mobile2 : this.data.mobile2,
      relation2 : this.data.relation2,
      real_name : this.data.real_name,
      mobile : this.data.mobile,
      idcard : this.data.idcard,
      address : this.data.address,
      id : this.data.id
    }
    let that = this;
    App.http('post','/userinfo_complete_status',data,function(res){
      
      if(res.code==1){
        getApp().globalData.auth_status = 1;
        wx.showToast({
          title: '完成',
          icon:'success'
        })
        that.cancel();
        App.jump('../usercenter/usercenter');
      }else{
        wx.showToast({
          title: '失败',
          icon:'error'
        })
      }
    })
  },
  /**
   * 取消
   */
  cancel:function(){
    this.setData({
      edit_disable:true,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getUser();
  },
  /**
   * 获取用户信息
   */
  getUser(){
    let that = this;
    App.http('get','/userinfo_complete_status',{},function(res){
      that.setData({
          real_name : res.data.customer.real_name,
          mobile : res.data.customer.mobile,
          idcard : res.data.customer.idcard,
          address : res.data.customer.address,
          id : res.data.customer.customer_id
      })
      if(res.data.relation.length>0){
        that.setData({
          name1:res.data.relation[0].name,
          mobile1:res.data.relation[0].mobile,
          relation1:res.data.relation[0].relation_name,
          name2:res.data.relation[1].name,
          mobile2:res.data.relation[1].mobile,
          relation2:res.data.relation[1].relation_name,
      })
      }
    });
  },
 

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})